package com.yan.key;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by april on 16/12/27.
 * 5.2排行榜
 */

public class RankMiddleActivity extends AppCompatActivity {

    Context mContext;
    RecyclerView recyclerView;
    RankMiddleAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_cycle);
        recyclerView = (RecyclerView) findViewById(R.id.rc);
        mContext = this;
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        adapter = new RankMiddleAdapter(mContext);
        recyclerView.setAdapter(adapter);
    }


    class RankMiddleAdapter extends RecyclerView.Adapter<RankMiddleAdapter.ViewHolder> {



        private Context context;
        private LayoutInflater inflater;

        public RankMiddleAdapter(Context context) {
            this.context = context;
            this.inflater = LayoutInflater.from(context);
        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LinearLayout ll = new LinearLayout(context);
            ll.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ll.setLayoutParams(lp);
            return new ViewHolder(ll);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            TabLayout tabLayout = new TabLayout(context);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100);
            tabLayout.setLayoutParams(lp);
            LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500);
            FrameLayout vp = new FrameLayout(context);
            vp.setLayoutParams(lp1);
            holder.ll.addView(vp);
            holder.ll.addView(tabLayout);
            List<TempFg> fgList;
            List<String> titles;
            FgAdapter fgAdapter;
            titles = new ArrayList<>();
            titles.add("分公司");
            titles.add("服务中心");
            titles.add("房管员");

            fgList = new ArrayList<>();
            TempFg fragmentCompany = new TempFg();
            TempFg fragmentServiceCenter = new TempFg();
            TempFg fragmentFgy = new TempFg();

            fgList.add(fragmentCompany);
            fgList.add(fragmentServiceCenter);
            fgList.add(fragmentFgy);
            ViewPager viewPager = new ViewPager(context);
            viewPager.setId(position + (int) Math.random() + 1);
            vp.addView(viewPager);
            fgAdapter = new FgAdapter(getSupportFragmentManager(), titles, fgList);
            viewPager.setAdapter(fgAdapter);
            tabLayout.setupWithViewPager(viewPager);


        }




        @Override
        public int getItemCount() {
            return 5;
        }

        public class ViewHolder extends RecyclerView.ViewHolder {


            LinearLayout ll;

            public ViewHolder(View itemView) {
                super(itemView);

                ll = (LinearLayout) itemView;
//                ll = (LinearLayout) itemView.findViewById(R.id.ll);
//                vp = (FrameLayout) itemView.findViewById(R.id.vp);
//                tabLayout = (TabLayout) itemView.findViewById(R.id.tab);

            }
        }

    }

}
